package com.leetcode.LC;

import java.util.Arrays;

public class LC645 {
    public int[] findErrorNums(int[] nums) {
        Arrays.sort(nums);
        int[] ints = new int[2];
        int sum = 0;
        boolean tmp = false;
        for (int i = 0; i < nums.length; i++) {
            if (tmp == false && nums[i] == nums[i + 1]) {
                ints[0] = nums[i];
                tmp = true;
            }
            sum += nums[i];
        }
        ints[1] = ints[0] + ((nums.length + (nums.length * (nums.length - 1)) / 2) - sum);
        return ints;
    }

    public static void main(String[] args) {
        for (int errorNum : new LC645().findErrorNums(new int[]{1, 2, 4, 4})) {
            System.out.print(errorNum + ",");
        }
    }
}
